package com.sixth.controller;

import com.sixth.entity.Stat;
import com.sixth.service.StatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: Keyboard-5
 * @description:
 * @author: 老范
 * @create: 2022-01-17 15:47
 **/
@RestController
@RequestMapping("stat")
public class StatController {
    @Autowired
    private StatService statService;

    //加载客户地区数据
    @RequestMapping("loadCustomerAreaStat")
    @ResponseBody
    public List<Stat> loadCustomerAreaStat(){
        return statService.loadCustomerAreaStat();
    }
    //加载公司年度月份业务统计数据
    @RequestMapping("loadCompanyYearGradeStat")
    @ResponseBody
    public List<Double> loadCompanyYearGradeStat(String year){
        List<Double> entities = statService.loadCompanyYearGradeStatList(year);
        for (int i = 0; i < entities.size(); i++) {
            if (null==entities.get(i)){
                entities.set(i,0.0);
            }
        }
        return entities;
    }
    //加载业务员年度业务统计数据
    @RequestMapping("loadOpernameYearGradeStat")
    @ResponseBody
    public Map<String,Object> loadOpernameYearGradeStat(String year){
        List<Stat> entities = statService.loadOpernameYearGradeStatList(year);
        Map<String,Object> map = new HashMap<String, Object>();
        List<String> names = new ArrayList<String>();
        List<Double> values = new ArrayList<Double>();
        for (Stat baseEntity : entities) {
            names.add(baseEntity.getName());
            values.add(baseEntity.getValue());
        }
        map.put("name",names);
        map.put("value",values);
        return map;
    }

}
